import java.lang.RuntimeException

open class Vehicle(val year:Int, open var color:String){
    open val km = 0
    final override fun toString(): String {
        return "year:$year,Color:$color,KM:$km"
    }
    fun repaint(newColor:String){
        color = newColor
    }
}

open class Car(year:Int,color:String) :Vehicle(year,color){
    override var km:Int = 0
    set(value) {
        if(value < 1){
            throw RuntimeException("can not set negtive value")
        }else{
            field = value
        }
    }
    fun drive(distance:Int){
        km += distance
    }
}

val benchiCar = Car(2000,"white")
benchiCar.drive(1000)
println(benchiCar)
//benchiCar.km = 0
benchiCar.drive(0)